package jp.sourceforge.akjrcp.dropsomething;

import java.io.File;
import java.io.FilenameFilter;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.ui.SimpleFileList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;

public class ProgressAndList extends Composite{
	
	private SimpleFileList fileList;
	private Button cancelButton;

	private FilenameFilter filenameFilter;
	private ProgressBar progressBar;
	private Label centerLabel;
	private Label headerLabel;
	public FilenameFilter getFilenameFilter() {
		return filenameFilter;
	}
	public void setFilenameFilter(FilenameFilter filenameFilter) {
		this.filenameFilter = filenameFilter;
	}
	public ProgressAndList(Composite parent, int style) {
		super(parent, style);
		this.setLayout(new GridLayout(1,false));
		
		headerLabel=new Label(this,SWT.NULL);
		headerLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		Composite bar_and_cancel=new Composite(this,SWT.NONE);
		bar_and_cancel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		bar_and_cancel.setLayout(new GridLayout(2,false));
		
		
		
		progressBar = new ProgressBar(bar_and_cancel,SWT.NONE);
		progressBar.setMaximum(100);
		
		//TODO:should work;
		progressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		cancelButton = new Button(bar_and_cancel,SWT.NULL);
		cancelButton.setText(Messages.getString("cancel"));
		
		centerLabel=new Label(this,SWT.NULL);
		centerLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		fileList = new SimpleFileList(this,SWT.NULL);
		fileList.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
	}
	public void setHeaderLabelText(String text){
		headerLabel.setText(text);
	}
	public void setCenterLabelText(String text){
		centerLabel.setText(text);
	}
	public void addFile(String path){
		File file=new File(path);
		if(filenameFilter==null || filenameFilter.accept(file.getParentFile(), file.getName())){
			fileList.addFile(file);	
		}
		
	}
	public SimpleFileList getSimpleFileList(){
		return fileList;
	}
	public Button getCancelButton(){
		return cancelButton;
	}
	public ProgressBar getProgressBar() {
		return progressBar;
	}
	

	
}
